package com.jdzy.utils.common;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class ParseToListOrStringUtils {

    /**
     * 将字符串str以splitIndex分割转换为List对象
     * @param str
     * @param splitIndex
     * @return
     */
    public static List<String> parseToListWithString(String str,String splitIndex){
        if(StringUtils.isBlank(str)){
            return new ArrayList<>();
        }
        return Arrays.asList(str.split(splitIndex));
    }

    /**
     * 将stringList以splitIndex为符号化为字符串
     * @param stringList
     * @param splitIndex
     * @return
     */
    public static String parseToString(List<String> stringList,String splitIndex){
        return stringList.stream().collect(Collectors.joining(splitIndex));
    }

}
